package com.qualitair44.activity;

import java.util.ArrayList;

import com.qualitair44.R;
import com.qualitair44.constantes.Constantes;
import com.qualitair44.faqlist.MyExpandableListItem;
import com.qualitair44.faqlist.MyExpandableListAdapter;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupClickListener;

public class FAQActivity extends Activity  implements Runnable {

	private MyExpandableListAdapter adapter;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.faq_layout);

		ExpandableListView listView = (ExpandableListView) findViewById(R.id.expandableListViewFAQ);

		listView.setOnChildClickListener(new OnChildClickListener() {

			@Override
			public boolean onChildClick(ExpandableListView parent, View v,
					int groupPosition, int childPosition, long id) {
				// TODO Auto-generated method stub
				return false;
			}
		});

		listView.setOnGroupClickListener(new OnGroupClickListener() {
			@Override
			public boolean onGroupClick(ExpandableListView parent, View v,
					int groupPosition, long id) {
				// TODO Auto-generated method stub
				return false;
			}
		});

		// Initialize the adapter with blank groups and children
		// We will be adding children on a thread, and then update the ListView
		adapter = new MyExpandableListAdapter(this, new ArrayList<String>(),
				new ArrayList<ArrayList<MyExpandableListItem>>());

		// Set this blank adapter to the list view
		listView.setAdapter(adapter);
		Thread thread = new Thread(this);
		thread.start();
	}

	@Override
	public void run() {
		// TODO Remplir liste

		for(int i = 0; i<Constantes.answersFAQ.length; i++){
			adapter.addItem(
					new MyExpandableListItem(
							Constantes.questionsFAQ[i],
							Constantes.answersFAQ[i]
							)
					);
		}

		// Notify the adapter
		handler.sendEmptyMessage(1);
	}

	private Handler handler = new Handler()
	{
		@Override
		public void handleMessage(Message msg)
		{
			adapter.notifyDataSetChanged();
			super.handleMessage(msg);
		}
	};

}
